package com.mrjy.maintain.bo;

import com.mrjy.common.entity.GloryInfo;
import com.mrjy.maintain.dao.IGloryInfoDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("gloryInfoBo")
public class GloryInfoBo implements IGloryInfoBo {
    @Resource
    private IGloryInfoDao gloryInfoDao;

    @Override
    public Object txInsert(GloryInfo info) {
        Map<String, Object> map = new HashMap<String, Object>();

        if (info.getUserId() == null || info.getTypeId() == null) {
            map.put("err_code", 500);
            map.put("err_msg", "参数有误");
            return map;
        }

        int row = gloryInfoDao.insert(info);
        //设置更新时间
        if (row > 0) {
            map.put("err_code", 200);
            map.put("err_msg", "添加成功");
        } else {
            map.put("err_code", 500);
            map.put("err_msg", "添加失败");
        }
        return map;
    }

    @Override
    public Object txDeleteByIds(int[] ids) {
        Map<String, Object> map = new HashMap<String, Object>();
        int row = gloryInfoDao.deleteByIds(ids);
        //设置更新时间
        if (row > 0) {
            map.put("err_code", 200);
            map.put("err_msg", "删除成功");
        } else {
            map.put("err_code", 500);
            map.put("err_msg", "删除失败");
        }
        return map;
    }

    @Override
    public Object txUpdateById(GloryInfo info) {
        Map<String, Object> map = new HashMap<String, Object>();
        int row = gloryInfoDao.updateById(info);
        //设置更新时间
        if (row > 0) {
            map.put("err_code", 200);
            map.put("err_msg", "更新成功");
        } else {
            map.put("err_code", 500);
            map.put("err_msg", "更新失败");
        }
        return map;
    }


    @Override
    public Object txUpdateDisableFlag(GloryInfo info) {
        Map<String, Object> map = new HashMap<String, Object>();
        int row = gloryInfoDao.updateDisableFlag(info);
        //设置更新时间
        if (row > 0) {
            map.put("err_code", 200);
            map.put("err_msg", "更新成功");
        } else {
            map.put("err_code", 500);
            map.put("err_msg", "更新失败");
        }
        return map;
    }

    @Override
    public Object queryByUserId(GloryInfo info) {
        Map<String, Object> map = new HashMap<String, Object>();
        GloryInfo GloryInfo = gloryInfoDao.queryByUserId(info);
        //设置更新时间
        if (GloryInfo != null) {
            map.put("err_code", 200);
            map.put("err_msg", "查询成功");
            map.put("info", GloryInfo);
        } else {
            map.put("err_code", 500);
            map.put("err_msg", "查询失败");
        }
        return map;
    }

}
